Skip to content

Conversation

@Nixxx19
Copy link

@Nixxx19 Nixxx19 commented Dec 30, 2025

Fixes #3746

Problem

The downloadProjectAsZip function was calling buildZip without awaiting it, causing a 502 Bad Gateway error when downloading projects. This led to:

  • Unhandled promise rejections if buildZip threw errors
  • No timeout on S3 file fetches, causing requests to hang indefinitely
  • Race conditions when clients disconnected before completion

Changes Made

  • Added await to buildZip call in downloadProjectAsZip to ensure errors are properly caught and the function waits for completion before responding
  • Added 30-second timeout to axios requests when fetching files from S3 to prevent hanging requests
  • Improved error handling by checking res.headersSent before sending error responses to avoid crashes on client disconnects
  • Enhanced error logging with more descriptive error messages for better debugging

Testing

I have verified that this pull request:

  • has no linting errors (npm run lint)
  • has no test errors (npm run test)
  • has no typecheck errors (npm run typecheck)
  • is from a uniquely-named feature branch and is up to date with the develop branch.
  • is descriptively named and links to an issue number, i.e. Fixes #123
  • meets the standards outlined in the accessibility guidelines

@Nixxx19
Copy link
Author

Nixxx19 commented Dec 30, 2025

download.issue.fix.mov

Video Demonstration

I've included a video showing the download functionality working correctly after the fix:

Before the fix: Downloads would hang for ~1 minute and then show a 502 Bad Gateway error
After the fix: Downloads complete successfully and the zip file is generated properly

The video shows:

  • A p5.js sketch being downloaded
  • The download completing successfully
  • The zip file (clock_2025_12_30_16_13_37.zip, 5.2 MB) being saved without errors

This confirms that the changes resolve issue #3746.

@Jatin24062005
Copy link
Contributor

@Nixxx19 According to your video did u able to set the custom path of zip file in your machine????

@Jatin24062005
Copy link
Contributor

@Nixxx19 Thanks for working on this and adding timeouts to prevent hanging requests — that’s a good safety improvement for the backend.

However, this change does not fully address the 502 Bad Gateway issue observed when downloading projects.

The root cause appears to be that ZIP generation (including remote asset fetching and JSZip.generateAsync) is performed synchronously before any response headers are sent. When this process takes longer than Cloudflare’s gateway timeout, Cloudflare terminates the request and returns a 502 — even though the backend may still be working.

Adding axios timeouts helps avoid infinite waits inside the Node process, but it does not prevent Cloudflare from timing out while waiting for the origin to start responding.

Suggested improvement:

Send response headers immediately and stream the ZIP output (generateNodeStream) instead of buffering the entire archive in memory.

Alternatively, move ZIP generation to an async/background job and return a download link once ready.

Starting the response early ensures Cloudflare keeps the connection open and avoids gateway errors, while also reducing memory usage on the server.
Try to keep engaging Cloudflare rather than timeout What you thinks @raclim ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unable to download game

2 participants